import urllib, re, xbmcplugin, xbmcgui, os

#.nF0
__plugin__ = "Failblog"
__author__ = "Anders Brujordet"
__date__ = "06 02 2010"
__version__ = "1"

handle = sys.argv[1]
dialog = xbmcgui.Dialog()

def list_pics():
    LIMIT = 10
    counter = 1
    linkregex = re.compile('[\'|"](.*?)[\'"].*?')

    while counter < LIMIT:
        data = urllib.urlopen("http://failblog.org/page/" + str(counter)).read()
        links = linkregex.findall(data)

        for pic in links:
            if ".jpg" in pic and "files" in pic:
                listitem = xbmcgui.ListItem( os.path.basename(pic), iconImage="DefaultPicture.png", thumbnailImage=pic)
                listitem.setInfo( type="Picture", infoLabels={"Title": os.path.basename(pic)})
                xbmcplugin.addDirectoryItem( handle=int(handle), url=pic, listitem=listitem, isFolder=False, totalItems=(LIMIT*7))
        counter += 1

list_pics()
xbmcplugin.addSortMethod( handle=int(handle), sortMethod=xbmcplugin.SORT_METHOD_NONE)
xbmcplugin.endOfDirectory(int(handle))
